#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int a[N];
int d[N], s[N], t[N];
int b[N];
bool check(int x) {
  rep(i, 1, n) b[i] = 0;
  rep(i, 1, x) {
    b[s[i]] += d[i];
    b[t[i] + 1] -= d[i];
  }
  rep(i, 1, n) b[i] += b[i - 1];
  rep(i, 1, n) if (b[i] > a[i]) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, m) cin >> d[i] >> s[i] >> t[i];
  int l = 1, h = n;
  while (l <= h) {
    int mid = (l + h) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      h = mid - 1;
  }
  if (l > n)
    cout << 0;
  else
    cout << -1 << endl << l;
  return 0;
}